package com.sve.Controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.sve.Dao.RouteMapper;
import com.sve.Dao.TimeMapper;
import com.sve.Entity.Route;
import com.sve.Entity.Time;

@Controller
@RequestMapping("/Route")
public class RouteController {
	private RouteMapper routeservice;
	private TimeMapper timeservice;
	
	public TimeMapper getTimeservice() {
		return timeservice;
	}
	@Autowired
	public void setTimeservice(TimeMapper timeservice) {
		this.timeservice = timeservice;
	}

	public RouteMapper getRouteservice() {
		return routeservice;
	}

	@Autowired
	public void setRouteservice(RouteMapper routeservice) {
		this.routeservice = routeservice;
	}
	
	@RequestMapping("/BookingRoute")
	public String BookingRoute(Model model){
		List<Route> route=routeservice.selectRoute();
		model.addAttribute("Route", route);
		return "BookingRoute";
	}
	
	@RequestMapping("/addRoute")
	public String addRoute(Model model,String startStation,String destStation,Double price,String t){
		System.out.println("进来了");
		Route r = new Route();
		Time time = new Time ();
		time.setStarttime(t);
		r.setDestStation(destStation);
		r.setStartStation(startStation);
		r.setPrice(price);
		r.setTime(time);
		int num = timeservice.insert(time);
		System.out.println("insert :时间"+num);
		List<Time> timelist = timeservice.selectTimeRoute(t);
		r.setTimeid(timelist.get(0).getTimeid());
		int num1=routeservice.insert(r);
		System.out.println("insert_Route:"+num1);
		return "redirect:/Route/BookingRoute";
	}
}
